from django.conf import settings
from django.contrib import admin
from django.urls import path, include, re_path
from django.views import static
from drf_yasg import openapi
from drf_yasg.views import get_schema_view

# API-DOC
schema_view = get_schema_view(
    openapi.Info(
        title="SOP API 文档",
        default_version='v1',
        description=(
            "使用`swagger-ui`风格点[这里](/swagger/)。\n"
            "使用`ReDoc`风格点[这里](/redoc/)。\n"
            "[下载](/swagger.yaml)`YAML`格式文档。\n"
            "[下载](/swagger.json)`JSON`格式文档。\n"
        )
    ),
    public=True,
)

urlpatterns = [
    path('admin/', admin.site.urls),
    re_path(r'^static/(?P<path>.*)$', static.serve, {'document_root': settings.STATIC_ROOT}, name='static'),
    # account
    path('api/v1.0/account/', include('account.urls')),
    # file_manage
    path('api/v1.0/file_manage/', include('file_manage.urls')),
    # dictionary_mixins
    path('api/v1.0/dictionary/', include('dictionary.urls')),
    # permissions
    path('api/v1.0/permissions/', include('permissions.urls')),

]

urlpatterns += [
    # api-doc url
    re_path(
        r'^swagger(?P<format>\.json|\.yaml)$',
        getattr(schema_view, 'without_ui')(cache_timeout=0),
        name='schema-json'
    ),
    path(
        'swagger/',
        getattr(schema_view, 'with_ui')('swagger', cache_timeout=0),
        name='schema-swagger-ui'
    ),
    path(
        'redoc/',
        getattr(schema_view, 'with_ui')('redoc', cache_timeout=0),
        name='schema-redoc'
    ),
]
